﻿using TinaX;
using TinaX.UIKit;
using TinaX.Services;
using UnityEngine;

namespace Nekonya.Example
{
    public class AppBootstrap : IXBootstrap
    {
        public void OnInit(IXCore core) {
            XCore.MainInstance.Services.Singleton<IAssetService, XServerVFS>();
        }

        public void OnStart(IXCore core)
        {
            //vfs.DownloadWebAssetTimeout
            //open ui

            //Tell lua that TinaX was started
            var func = LuaMgr.luaEnv.Global.Get<XLua.LuaFunction>("TinaXOnStart");
            func.Call();
            func.Dispose();

            var uikit = XCore.MainInstance.GetService<IUIKit>(); //从XCore的全局单例中获取UIKit服务的接口
            uikit.OpenUIAsync("mainScreen", new MainScreen());


            var obj1 = XRes.CreateInstanceSync("Assets/Res/Prefab/Test/Test1.prefab");
            var obj2 = XRes.CreateInstanceSync("Assets/Res/Prefab/Test/Test2.prefab");
            obj2.transform.SetParent(obj1.transform, false);
            obj1.GetComponent<TestUpdateScript>().refObj = obj2;
        }

        public void OnQuit() { }

        public void OnAppRestart() { }


    }
}
